# !/usr/bin/env python
# -*-coding:utf-8 -*-
"""
# File       : schedule_plan_models.py
# Time       ：2023/7/7 21:38
# Author     ：Y-aong
# version    ：python 3.7
# Description：
    定时计划模型类
    Timing schedule class
"""
from public.base_model import Base, db


class IntervalPlan(Base):
    __tablename__ = 'schedule_interval_plan'

    job_id = db.Column(db.String(255), unique=True, comment='任务ID')
    weeks = db.Column(db.Integer, comment='间隔时间类型-周')
    days = db.Column(db.Integer, comment='间隔时间类型-天')
    hours = db.Column(db.Integer, comment='间隔时间类型-小时')
    minutes = db.Column(db.Integer, comment='间隔时间类型-分钟')
    seconds = db.Column(db.Integer, comment='间隔时间类型-秒')
    start_date = db.Column(db.DateTime, comment='间隔计算的起始时间点')
    end_date = db.Column(db.DateTime, comment='触发的最晚日期/时间')
    timezone = db.Column(db.String(64), default="Asia/Shanghai", comment='时区')


class DatePlan(Base):
    __tablename__ = 'schedule_date_plan'

    job_id = db.Column(db.String(255), unique=True, comment='任务ID')
    run_date = db.Column(db.DateTime, comment='计划运行时间')
    timezone = db.Column(db.String(64), default="Asia/Shanghai", comment='时区')


class CrontabPlan(Base):
    __tablename__ = 'schedule_crontab_plan'

    job_id = db.Column(db.String(255), unique=True, comment='任务ID')
    year = db.Column(db.String(32), comment='四位年份')
    month = db.Column(db.String(32), comment='月份，取值范围为1-12')
    day = db.Column(db.String(32), comment='日期，取值范围为1-31')
    week = db.Column(db.String(32), comment='星期，形如2006-12-31或2006-W52-7或2006W527')
    day_of_week = db.Column(db.String(32), comment='星期几，0-6或mon,tue,wed,thu,fri,sat,sun')
    hour = db.Column(db.String(32), comment='小时，取值范围为0-23')
    minute = db.Column(db.String(32), comment='分钟，取值范围为0-59')
    second = db.Column(db.String(32), comment='秒，取值范围为0-59')
    timezone = db.Column(db.String(64), default="Asia/Shanghai", comment='时区')
    start_date = db.Column(db.DateTime, comment='间隔计算的起始时间点')
    end_date = db.Column(db.DateTime, comment='触发的最晚日期/时间')


class ApschedulerJobs(db.Model):
    __tablename__ = 'apscheduler_jobs'

    id = db.Column(db.Unicode(191), primary_key=True)
    next_run_time = db.Column(db.Float(25), index=True)
    job_state = db.Column(db.LargeBinary, nullable=False, comment='任务状态')
